<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var Modal = function (sex) {
        //     this.sex = sex
        //     this.clothes = clothes
        // }
        // Modal.prototype.takePhoto = function () {
        //     console.log("sex =" + this.sex + "衣服: " + this.clothes)
        // }


        // for (let i = 0; i < 50; i++) {
        //     var modal = new Modal("male", "clothes" + i)
        //     modal.takePhoto()
        // }

        // for (let j = 0; j < 50; j++) {
        //     var modal = new Modal("female", "clothes" + j)
        //     modal.takePhoto()

        // }
        //享元模式
        var Modal = function (sex) {
            this.sex = sex
        }

        Modal.prototype.takePhoto = function () {
            console.log("sex =" + this.sex + "衣服:" + this.clothes)
        }

        var maleModal = new Modal("male")
        var femaleModal = new Modal("female")



        for (let i = 0; i < 50; i++) {
            maleModal.clothes = "衣服:" + i
            maleModal.takePhoto()
        }

        for (let j = 0; j < 50; j++) {
            femaleModal.clothes = "衣服:" + j
            femaleModal.takePhoto()
        }
    </script>
</body>

</html>